<!-- extend from base layout -->
{% extends "layout.html" %}

{% block extra_css %}

{% endblock %}

{% block content %}
    <div class="container-fluid">
    <ol class="breadcrumb">
        <li><a href="/">后台管理</a></li>
        <li><a href="javascript:void(0);" onclick="$('#menu-order').trigger('click');">订单管理</a></li>
        <li class="active">提现列表</li>
    </ol>

    <form class="form-inline">
        <div class="form-group{% if form.apply_get_id.errors %} has-error{% endif %}">
            {{ form.apply_get_id.label(class="sr-only") }}
            {{ form.apply_get_id(class="form-control", placeholder="提现申请ID") }}
            {% for error in form.apply_get_id.errors %}
                <span class="help-block">{{ error }}</span>
            {% endfor %}
        </div>
        <div class="form-group{% if form.user_id.errors %} has-error{% endif %}">
            {{ form.user_id.label(class="sr-only") }}
            {{ form.user_id(class="form-control", placeholder="用户ID") }}
            {% for error in form.user_id.errors %}
                <span class="help-block">{{ error }}</span>
            {% endfor %}
        </div>
        <div class="form-group{% if form.type_apply.errors %} has-error{% endif %}">
            {{ form.type_apply.label(class="sr-only") }}
            {{ form.type_apply(class="form-control", placeholder="申请类型", data_width="fit", data_header="选择类型") }}
            {% for error in form.type_apply.errors %}
                <span class="help-block">{{ error }}</span>
            {% endfor %}
        </div>
        <div class="form-group{% if form.status_order.errors %} has-error{% endif %}">
            {{ form.status_order.label(class="sr-only") }}
            {{ form.status_order(class="form-control", placeholder="订单状态", data_width="fit", data_header="选择状态") }}
            {% for error in form.status_order.errors %}
                <span class="help-block">{{ error }}</span>
            {% endfor %}
        </div>
        <div class="form-group{% if form.status_delete.errors %} has-error{% endif %}">
            {{ form.status_delete.label(class="sr-only") }}
            {{ form.status_delete(class="form-control", placeholder="删除状态", data_width="fit", data_header="选择状态") }}
            {% for error in form.status_delete.errors %}
                <span class="help-block">{{ error }}</span>
            {% endfor %}
        </div>
        <div class="form-group{% if form.start_time.errors %} has-error{% endif %}">
            {{ form.start_time.label(class="sr-only") }}
            {{ form.start_time(class="form-control", placeholder="start_time", type='date') }}
            {% for error in form.start_time.errors %}
                <span class="help-block">{{ error }}</span>
            {% endfor %}
        </div>
        <div class="form-group{% if form.end_time.errors %} has-error{% endif %}">
            {{ form.end_time.label(class="sr-only") }}
            {{ form.end_time(class="form-control", placeholder="end_time", type='date') }}
            {% for error in form.end_time.errors %}
                <span class="help-block">{{ error }}</span>
            {% endfor %}
        </div>

        <button type="submit" class="btn btn-primary" name="op" value="0">Search</button>
        <button type="submit" class="btn btn-primary" name="op" value="1">Export</button>
    </form>

    <hr/>

    <div class="table-responsive">
        {# <table class="table table-striped"> #}
        <table class="table table-hover">
            <thead>
            <tr>
                <th>ID</th>
                <th>用户ID</th>
                <th>用户名称</th>
                <th>申请类型</th>
                <th>申请金额</th>
                <th>订单金额</th>
                <th>申请状态</th>
                <th>订单状态</th>
                <th>删除状态</th>
                <th>申请时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {% for apply_get, user_profile in pagination.items %}
            <tr class="text-muted">
                <td>{{ apply_get.id }}</td>
                <td>{{ apply_get.user_id }}</td>
                <td>{{ user_profile.nickname }}</td>
                <td>{{ apply_get.type_apply | type_apply }}</td>
                <td>{{ apply_get.money_apply }}</td>
                <td>{{ apply_get.money_order }}</td>
                <td>{{ apply_get.status_apply | status_apply }}</td>
                <td>{{ apply_get.status_order | status_order }}</td>
                <td>{{ apply_get.status_delete | status_delete }}</td>
                <td>{{ moment(apply_get.create_time).format('YYYY-MM-DD HH:mm:ss') }}</td>
                <td>
                    <a href="{{ url_for('apply_get.info', apply_get_id=apply_get.id) }}" rel="tooltip" title="匹配"><span class="glyphicon glyphicon-retweet"></span></a>
                    <a href="javascript:void(0);" onclick="apply_get_delete({{ apply_get.id }});" rel="tooltip" title="删除"><span class="glyphicon glyphicon-trash"></span></a>
                </td>
            </tr>
            {% endfor %}
            </tbody>
        </table>
        {# 翻页 #}
        {% from "macros.html" import render_pagination %}
        {{ render_pagination(pagination, 'apply_get.lists') }}
    </div>
    </div>
{% endblock %}

{% block extra_js %}
<script>
    // 初始化赋值
    var type_apply = $('#type_apply');
    type_apply.selectpicker('val', '{{ form.type_apply.data }}');
    // 处理选项修改
    type_apply.on('changed.bs.select', function (event, clickedIndex, newValue, oldValue) {
        // console.log($('#type_apply').val());
        // console.log(event);
        // console.log(clickedIndex);
        // console.log(newValue);
        // console.log(oldValue);
    });

    var status_order = $('#status_order');
    status_order.selectpicker('val', '{{ form.status_order.data }}');
    // 处理选项修改
    status_order.on('changed.bs.select', function (event, clickedIndex, newValue, oldValue) {
        // console.log($('#status_order').val());
        // console.log(event);
        // console.log(clickedIndex);
        // console.log(newValue);
        // console.log(oldValue);
    });

    var status_delete = $('#status_delete');
    status_delete.selectpicker('val', '{{ form.status_delete.data }}');
    // 处理选项修改
    status_delete.on('changed.bs.select', function (event, clickedIndex, newValue, oldValue) {
        // console.log($('#status_delete').val());
        // console.log(event);
        // console.log(clickedIndex);
        // console.log(newValue);
        // console.log(oldValue);
    });

    // 提现删除
    function apply_get_delete(apply_get_id){
        if(confirm("删除数据不能恢复，是否确认删除?"))
        {
            // console.log(apply_get_id);
            $.getJSON('{{ url_for('apply_get.ajax_delete') }}',
            {
                apply_get_id: apply_get_id
            }, function (result) {
                if(result.hasOwnProperty('error')){
                    alert(result.error);
                }else {
                    alert(result.success);
                    window.location.reload();
                }
            });
            return false;
        }
    }
</script>
{% endblock %}
